﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using A2DFramework.SQLDispatcherService;
using A2DFramework.SQLDispatcherService.Configuration;
using System.Data.SqlClient;
using CLFramework.Data;

namespace Demo.SqlDispatcherConsole
{
    class Query1
    {
        public void Test_2Write()
        {
            using (var conn = ConnectionManager.GetSqlConnection(ConnectionOption.Create("DB1", SqlExecuteType.Write)))
            {
                SqlHelper.ExecuteNonQuery(conn, "dbo.up_insert", DateTime.Now.ToString());
            }

            using (var conn = ConnectionManager.GetSqlConnection(ConnectionOption.Create("DB1", SqlExecuteType.Write)))
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(conn, "dbo.up2_select1", 100);
                reader.Read();
                reader.Close();
                reader.Dispose();
            }
        }

        public void Test_1Read1Write()
        {
            using (var conn = ConnectionManager.GetSqlConnection(ConnectionOption.Create("DB1", SqlExecuteType.Write)))
            {
                SqlHelper.ExecuteNonQuery(conn, "dbo.up_insert", DateTime.Now.ToString());
            }

            using (var conn = ConnectionManager.GetSqlConnection(ConnectionOption.Create("DB1", SqlExecuteType.Read)))
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(conn, "dbo.up2_select1", 100);
                reader.Read();
                reader.Close();
                reader.Dispose();
            }
        }

        //public void Test2()
        //{
        //    using (var conn = ConnectionManager.GetSqlConnection(ConnectionOption.Create("DB1", "Sales")))
        //    {
        //        SqlDataReader reader = SqlHelper.ExecuteReader(conn, "dbo.up2_select2", 100);
        //        reader.Read();
        //        reader.Close();
        //        reader.Dispose();
        //    }
        //}
    }
}
